/**
 * class to represent a planet
 */
import java.util.Random;
/**
 * @author Zhenyi Zhu
 * @version $Revision: 1.0 $
 */
public class Planet {

	/**
	 * Field SHIBA.
	 * (value is 18)
	 */
	private static final int SHIBA = 18;

	/**
	 * Field SHIQI.
	 * (value is 17)
	 */
	private static final int SHIQIA = 17;

	/**
	 * Field SHILIU.
	 * (value is 16)
	 */
	private static final int SHILIU = 16;

	/**
	 * Field SHIWU.
	 * (value is 15)
	 */
	private static final int SHIWU = 15;

	/**
	 * Field SHISI.
	 * (value is 14)
	 */
	private static final int SHISIAA = 14;

	/**
	 * Field SHISAN.
	 * (value is 13)
	 */
	private static final int SHISAN = 13;

	/**
	 * Field SHIER.
	 * (value is 12)
	 */
	private static final int SHIER = 12;

	/**
	 * Field SHIYI.
	 * (value is 11)
	 */
	private static final int SHIYI = 11;

	/**
	 * Field ERSHIWAN.
	 * (value is 200000)
	 */
	private static final int ERSHIWAN = 200000;

	/**
	 * Field JIU.
	 * (value is 9)
	 */
	private static final int JIU = 9;

	/**
	 * Field BA.
	 * (value is 8)
	 */
	private static final int BA = 8;

	/**
	 * Field QI.
	 * (value is 7)
	 */
	private static final int QI = 7;

	/**
	 * Field LIU.
	 * (value is 6)
	 */
	private static final int LIU = 6;

	/**
	 * Field WU.
	 * (value is 5)
	 */
	private static final int WU = 5;

	/**
	 * Field SI.
	 * (value is 4)
	 */
	private static final int SI = 4;

	/**
	 * Field YIBAI.
	 * (value is 100)
	 */
	private static final int YIBAI = 100;

	/**
	 * Field SANSHI.
	 * (value is 30)
	 */
	private static final int SANSHI = 30;

	/**
	 * Field YIWAN.
	 * (value is 10000)
	 */
	private static final int YIWAN = 10000;

	/**
	 * Field JIUSHI.
	 * (value is 90)
	 */
	private static final int JIUSHI = 90;

	/**
	 * Field SISHI.
	 * (value is 40)
	 */
	private static final int SISHI = 40;

	/**
	 * Field SAN.
	 * (value is 3)
	 */
	private static final int SAN = 3;

	/**
	 * Field ER.
	 * (value is 2)
	 */
	private static final int ER = 2;

	/**
	 * Field ERSHI.
	 * (value is 20)
	 */
	private static final int ERSHI = 20;

	/**
	 * Field ERBAILINGYI.
	 * (value is 201)
	 */
	private static final int ERBAILINGYI = 201;

	/**
	 * Field YIBAIWANDIANLING.
	 * (value is 1000000.0)
	 */
	private static final double YIBAIWANDIANLING = 1000000.0;

	/**
	 * Field YIBAIDIANLING.
	 * (value is 100.0)
	 */
	private static final double YIBAIDIANLING = 100.0;

	/**
	 * Field SIDIANLING.
	 * (value is 4.0)
	 */
	private static final double SIDIANLING = 4.0;

	/**
	 * Field LINGDIANLINGYI.
	 * (value is 0.01)
	 */
	private static final double LINGDIANLINGYI = 0.01;

	/**
	 * Field SHI.
	 * (value is 10)
	 */
	private static final int SHI = 10;

	/**
	 * Field name.
	 */
	private String name;

	/**
	 * Field government.
	 */
	private static Government GovernmentIns=null;

	/**
	 * Field r.
	 */
	private final Random rand;

	/**
	 * Field taxRatio.
	 */
	private double taxRatio;

	/**
	 * Field chanceToEncounterPirates.
	 */
	private double chanceToEncounterPirates;

	/**
	 * Field chanceOfSavedByPolice.
	 */
	private double chanceOfSavedByPolice;

	/**
	 * Field chanceOfBeatPirates.
	 */
	private double chanceOfBeatPirates;

	/**
	 * Field moneyRobbedByPirates.
	 */
	private double moneyRobbedByPirates;

	/**
	 * Field chanceOfGetMoney.
	 */
	private double chanceOfGetMoney;

	/**
	 * Field solarSystem.
	 */
	private SolarSystem solarSystem;

	/**
	 * Field x.
	 */
	private int x;

	/**
	 * Field y.
	 */
	private int y;

	/**
	 * Field planetVar.
	 */
	private final int[] planetVar;

	/**
	 * Field specialCondition.
	 */
	private int specialCondition;
	
	/**
	 * Constructor for Planet.
	 * @param name String
	 * @param solarSystem SolarSystem
	 * @param x int
	 * @param y int
	 */
	public Planet(String name, SolarSystem solarSystem, int x, int y){ 

		GovernmentIns=new Government((x + y) % SHI);
		PlayerInfo.CurrentPlanet=this;
		rand=new Random();
		this.name=name;
		this.x=x;
		this.y=y;
		this.solarSystem=solarSystem;
		this.taxRatio=LINGDIANLINGYI;

		this.chanceOfBeatPirates=GameInfo.getFighterSP() * SIDIANLING;

		this.chanceOfBeatPirates=GameInfo.getFighterSP();

		this.chanceOfSavedByPolice=(SHI + 
				GameInfo.Rand.nextInt(SISHI)) / YIBAIDIANLING;
		this.chanceToEncounterPirates=(0 + 
				GameInfo.Rand.nextInt(JIUSHI)) / YIBAIDIANLING;
		this.moneyRobbedByPirates=(YIWAN + 
				GameInfo.Rand.nextInt(ERSHIWAN)) / YIBAIWANDIANLING;
		this.chanceOfGetMoney=(1 + GameInfo.Rand.nextInt(SANSHI)) / YIBAIDIANLING;
		this.planetVar=new int[SHI];
		for (int i=0;i < SHI;i++) this.planetVar[i] = 
				GameInfo.Rand.nextInt(ERBAILINGYI) - YIBAI;
		updateSpecialCondition();
	}
	
	/**
	 * Method updateSpecialCondition.
	 */
	public void updateSpecialCondition(){
		updateSpecialCondition(ERSHI);
	}

	/**
	 * Method getChanceOfGetMoney.
	
	 * @return double */
	public double getChanceOfGetMoney() {
		return chanceOfGetMoney;
	}
	
	/**
	 * Method setChanceOfGetMoney.
	 * @param chanceOfGetMoney double
	 */
	public void setChanceOfGetMoney(double chanceOfGetMoney) {
		this.chanceOfGetMoney = chanceOfGetMoney;
	}
	
	/**
	 * Method updateSpecialCondition.
	 * @param n int
	 */
	public void updateSpecialCondition(int n){
		specialCondition=GameInfo.Rand.nextInt(n);
	}
	
	/**
	 * Method getSpecialConditionNo.
	
	 * @return int */
	public int getSpecialConditionNo(){
		return specialCondition;
	}
	
	/**
	 * Method getSpecialCondition.
	
	 * @return String */
	public String getSpecialCondition(){
		if (specialCondition == 0) return "Normal";
		if (specialCondition == 1) return "Drought";
		if (specialCondition == ER) return "Cold";
		if (specialCondition == SAN) return "Crop Fail";
		if (specialCondition == SI) return "War";
		if (specialCondition == WU) return "Boredom";
		if (specialCondition == LIU) return "Plague";
		if (specialCondition == QI) return "Lack of Workers";
		if (specialCondition == BA) return "Lots of Water";
		if (specialCondition == JIU) return "Rich Fauna";
		if (specialCondition == SHI) return "Rich Soil";
		if (specialCondition == SHIYI) return "Mineral Rich";
		if (specialCondition == SHIER) return "Artistic";
		if (specialCondition == SHISAN) return "Warlike";
		if (specialCondition == SHISIAA) return "Lots of Herbs";
		if (specialCondition == SHIWU) return "Weird Mushrooms";
		if (specialCondition == SHILIU) return "Desert";
		if (specialCondition == SHIQIA) return "Lifeless";
		return specialCondition == SHIBA ? "Poor Soil" : "Mineral Poor";
	}
	
	/**
	 * Method getPlanetVar.
	 * @param pos int
	
	 * @return int */
	public int getPlanetVar(int pos) {
		return planetVar[pos];
	}

	/**
	 * Method setPlanetVar.
	 * @param value int
	 * @param pos int
	 */
	public void setPlanetVar(int value, int pos) {
		this.planetVar[pos] = value;
	}

	/**
	 * Method getX.
	
	 * @return int */
	public int getX() {
		return x;
	}

	/**
	 * Method setX.
	 * @param x int
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * Method getY.
	
	 * @return int */
	public int getY() {
		return y;
	}

	/**
	 * Method setY.
	 * @param y int
	 */
	public void setY(int y) {
		this.y = y;
	}

	/**
	 * Method getSolarSystem.
	
	 * @return SolarSystem */
	public SolarSystem getSolarSystem() {
		return solarSystem;
	}

	/**
	 * Method setSolarSystem.
	 * @param solarSystem SolarSystem
	 */
	public void setSolarSystem(SolarSystem solarSystem) {
		this.solarSystem = solarSystem;
	}

	/**
	 * Method getName.
	
	 * @return String */
	public String getName() {
		return name;
	}

	/**
	 * Method setName.
	 * @param name String
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Method getTaxRatio.
	
	 * @return double */
	public double getTaxRatio() {
		return taxRatio;
	}

	/**
	 * Method setTaxRatio.
	 * @param taxRatio double
	 */
	public void setTaxRatio(double taxRatio) {
		this.taxRatio = taxRatio;
	}

	/**
	 * Method getChanceToEncounterPirates.
	
	 * @return double */
	public double getChanceToEncounterPirates() {
		return chanceToEncounterPirates;
	}

	/**
	 * Method setChanceToEncounterPirates.
	 * @param chanceToEncounterPirates double
	 */
	public void setChanceToEncounterPirates(double chanceToEncounterPirates) {
		this.chanceToEncounterPirates = chanceToEncounterPirates;
	}

	/**
	 * Method getChanceOfSavedByPolice.
	
	 * @return double */
	public double getChanceOfSavedByPolice() {
		return chanceOfSavedByPolice;
	}

	/**
	 * Method setChanceOfSavedByPolice.
	 * @param chanceOfSavedByPolice double
	 */
	public void setChanceOfSavedByPolice(double chanceOfSavedByPolice) {
		this.chanceOfSavedByPolice = chanceOfSavedByPolice;
	}

	/**
	 * Method getChanceOfBeatPirates.
	
	 * @return double */
	public double getChanceOfBeatPirates(){
		//System.out.println(",,"+GameInfo.getFighterSP());
		return GameInfo.getFighterSP() * SIDIANLING;

		//System.out.println(",,"+GameInfo.getFighterSP());
	}

	/**
	 * Method getMoneyRobbedByPirates.
	
	 * @return double */
	public double getMoneyRobbedByPirates() {
		return moneyRobbedByPirates;
	}

	/**
	 * Method setMoneyRobbedByPirates.
	 * @param moneyRobbedByPirates int
	 */
	public void setMoneyRobbedByPirates(int moneyRobbedByPirates) {
		this.moneyRobbedByPirates = moneyRobbedByPirates;
	}

	/**
	 * Method upDateMoneyAfterTax.
	 */
	public void upDateMoneyAfterTax(){
		GovernmentIns.toSetTax();
	}

	/**
	 * Method getGovernment.
	
	 * @return Government */
	public static Government getGovernment(){
		return GovernmentIns;
	}

	/**
	 * Method toString.
	
	 * @return String */
	@Override
	public String toString() {
		return "Planet [name=" + name + ", taxRatio=" + taxRatio
				+ ", chanceToEncounterPirates=" + chanceToEncounterPirates
				+ ", chanceOfSavedByPolice=" + chanceOfSavedByPolice
				+ ", moneyRobbedByPirates=" + moneyRobbedByPirates + "]";
	}
	
}
